package com.sqx.modules.shop.controller.app;

import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.errand.entity.Feedback;
import com.sqx.modules.errand.service.ErrandComplaintService;
import com.sqx.modules.goods.entity.GoodsShop;
import com.sqx.modules.shop.service.ShopMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags={"商户端-商户管理"})
@RestController
@RequestMapping("/app/shop")
public class ShopMessageController {

    @Autowired
    private ShopMessageService shopMessageService;
    @Autowired
    private ErrandComplaintService errandComplaintService;

    @Login
    @ApiOperation("提交商户入驻申请")
    @PostMapping(value = "insertShopAuthentication")
    public Result insertShopAuthentication(@RequestAttribute Long userId, @RequestBody GoodsShop goodsShop){
        goodsShop.setUserId(userId);
        return shopMessageService.insertShopAuthentication(goodsShop);
    }

    @ApiOperation("商户入住发送验证码")
    @RequestMapping(value = "/sendMsgs/{phone}/{state}", method = RequestMethod.GET)
    @ResponseBody
    public Result sendMsgs(@PathVariable String phone,@ApiParam("验证码类型 state = enter") @PathVariable String state) {
        return shopMessageService.sendMsgs(phone, state);
    }

    @ApiOperation("用户端发送验证码")
    @RequestMapping(value = "/sendMsg/{phone}/{state}", method = RequestMethod.GET)
    @ResponseBody
    public Result sendMsg(@PathVariable String phone,@ApiParam("验证码类型 state = enter") @PathVariable String state) {
        return shopMessageService.sendMsg(phone, state);
    }


    @GetMapping(value = "selectShopAuthentication")
    @ApiOperation("入住信息回显")
    public Result selectShopAuthentication(String phone, String msg){

        return shopMessageService.selectShopAuthentication(phone, msg);
    }

    @Login
    @GetMapping(value = "selectShopByUserId")
    @ApiOperation("用户入驻商户信息回显")
    public Result selectShopByUserId(@RequestAttribute Long userId){

        return shopMessageService.selectShopByUserId(userId);
    }

    @ApiOperation("查看商户信息")
    @GetMapping(value = "selectShopMessage")
    public Result selectShopMessage(Long shopId){

        return shopMessageService.selectShopMessage(shopId);
    }

    @ApiOperation("修改商铺信息")
    @PostMapping(value = "updateShopMessage")
    public Result updateShopMessage(@RequestBody GoodsShop goodsShop){

        return shopMessageService.updateShopMessage(goodsShop);
    }

    @ApiOperation("商户收益统计")
    @GetMapping(value = "shopEarnings")
    public Result shopEarnings(Long shopId){

        return shopMessageService.shopEarnings(shopId);
    }

    @ApiOperation("商户主页")
    @GetMapping(value = "shopHomePage")
    public Result shopHomePage(Long shopId, String startTime, String endTime){

        return shopMessageService.shopHomePage(shopId, startTime, endTime);
    }

    @ApiOperation("商户退保证金")
    @GetMapping(value = "shopRefundCashDeposit")
    public Result shopRefundCashDeposit(Long shopId){

        return shopMessageService.shopRefundCashDeposit(shopId);
    }

    @PostMapping(value = "/userFeedback")
    @ApiOperation("商户反馈")
    public Result userFeedback(@RequestBody Feedback feedback){

        return shopMessageService.userFeedback(feedback);
    }

    @ApiOperation("商户查看所有投诉")
    @GetMapping(value = "selectComplaint")
    public Result selectComplaint(Long shopId, Integer page, Integer limit){

        return shopMessageService.selectComplaint(shopId, page, limit);
    }

    @ApiOperation("商户查看所有投诉详情")
    @GetMapping(value = "findComplaint")
    public Result findComplaint(Long complaintId){
        return errandComplaintService.findComplaint(null, complaintId);
    }



}
